# -*- coding:utf-8 -*-
"""
@author: freetere
@file: by_background.py
@time: 2020/4/15 10:47
"""
import os
import time
import requests
from bs4 import BeautifulSoup


try:
    os.mkdir('./{}'.format('biying'))
except:
    pass
baseUrl = 'https://cn.bing.com'
header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36',
}
response = requests.get(baseUrl, headers=header)
soup = BeautifulSoup(response.text, 'lxml')
div = soup.select('div[class="img_cont"]')
# print(div)
style = div[0]["style"]
address = style.split(')')[0]
address = address.split('(')[1]
# print(address)

response = requests.get(baseUrl+address, headers=header)
times = time.localtime()
pathName = '{}/{}-{}-{}.jpg'.format('biying', times[0], times[1], times[2])
print('每日运行一次即可获取必应浏览器今日高清背景图片')
print()
print('\n获取中~~~~~~~~')

with open(pathName, 'wb') as f:
    f.write(response.content)
    print('Successful!\n今日壁纸已保存为{}'.format(pathName))
time.sleep(4)











